home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / CFONT100.ZIP / CFONT.DOC < prev    next >
Encoding:
Text File  |  1995-07-07  |  8.6 KB  |  182 lines

  1.  
  2.                       ColorFont Library for Turbo C++
  3.       ==================================================================
  4.       Written by Nikolai Soumarokov           Version 1.00, July 7, 1995
  5.       ------------------------------------------------------------------
  6.  
  7.       This library is Public Domain. You are encouraged to make copies
  8.       of this library, to give it to other people, to upload it to FTP
  9.       sites and to BBS's, to put it on CD-ROMs, etc., as long as you
  10.       distribute the program in its original form, that is you distribute
  11.       all the program files together and do not modify them in any way. 
  12.       The program files are:
  13.  
  14.       3DFONT   FNT    sample font used by the demonstration program
  15.       BIGFONT  FNT    - " - (you can use them freely in your programs)
  16.       CFONT    LIB    the library itself
  17.       CFONT    DOC    this documentation
  18.       FONTDEMO CPP    demonstration program source 
  19.       FONTDEMO EXE    demonstration program
  20.       DEFAULT  PAL    color palette used by the demonstration program
  21.       CFONT    H      library header file
  22.  
  23.       Under no circumstances is this program to be sold. No payment
  24.       to the author is required for using this software. However, if
  25.       you write a program using this library, I would appreciate if
  26.       you give me some credit in the program itself or in its
  27.       documentation. Sending me a copy of the program would be nice, too.
  28.  
  29.       The ColorFont library is provided AS IS. The author specifically 
  30.       disclaims any responsibility for any loss of profit or any 
  31.       incidental, consequential or other damages. I did not program
  32.       this library to do anything harmful, but if something happens, I
  33.       am not responsible for that. Also, while the program works 
  34.       fine on my PC with Turbo C++ 3.0, I do not guarantee it will work 
  35.       on other machines or with other compilers.
  36.  
  37.       =================================================================
  38.  
  39.       Sorry for this excuse for documentation, but after I spent 1 day
  40.       writing the library itself and 1 week writing the demonstration
  41.       program, I don't want to spend another month writing the docs :)
  42.  
  43.       Most of the library's features must be clear from the demonstration
  44.       program's source, so here are just a few additional notes:
  45.  
  46.       ----------
  47.       The library reads fonts created with my very own GNOOM II sprite
  48.       editor. While I see no reason why you should use another program
  49.       for drawing fonts, here is the structure of the file created
  50.       by GNOOM II:
  51.  
  52.       byte 1: Number of characters in the font
  53.           NOTE: To have a file containing more than 24 characters,
  54.           you need to use the GNJOIN utility introduced in GNOOM II
  55.           version 1.02 (June 1995)
  56.       byte 2: Character width in pixels
  57.       byte 3: Character height in pixels
  58.       other:  Each character in raw format (1 byte per pixel, rows
  59.           from top to bottom, columns from left to right)
  60.  
  61.       The latest version of GNOOM II is available from x2ftp.oulu.fi.
  62.       Look for the file called GN2Vxxx.ZIP where xxx is the version
  63.       number.
  64.  
  65.       ----------
  66.       To load a font, just declare an object to be of class ColorFont.
  67.       You can open as many fonts as you want (or until your PC runs out
  68.       of memory).
  69.  
  70.       ----------
  71.       The following are the public variables and member functions of
  72.       the ColorFont class:
  73.  
  74.       int Font_NumOfChars;    // number of characters in the font.
  75.                 // set automatically - don't change it!
  76.  
  77.       int Font_CharWidth;    // dimensions of the font in pixels -
  78.       int Font_CharHeight;    // don't change them either!
  79.  
  80.       int Horiz_Spacing;    // horizontal and vertical spacing in pixels
  81.       int Vert_Spacing;        // use SetSpacing() function to change
  82.  
  83.       ColorFont (char *);    // constructor
  84.       ~ColorFont ();        // destructor
  85.  
  86.       void SetVideoAddress(unsigned char far *address);
  87.       void SetVideoAddress();
  88.       // used to set the starting address of the memory buffer (top left
  89.       // corner of the virtual page). Calling the function without 
  90.       // arguments sets the default - VGA screen address: A000:0000    
  91.  
  92.       void SetVScreenDim(unsigned int width, unsigned int height);
  93.       // sets dimensions of the virtual screen. Might be useful if you
  94.       // have scrolling. By default, equal to 320 and 200 (VGA screen size)
  95.  
  96.       void SetClipArea(unsigned int left, unsigned int right, 
  97.                unsigned int top, unsigned int bottom);
  98.       void SetClipArea();
  99.       // used to define the clipping area. By default (which can be restored
  100.       // by calling the function without arguments), equal to virtual page
  101.       // dimensions minus one (e.g. 0, 319, 0, 199)
  102.  
  103.       void SetSpacing(int horiz, int vert);
  104.       void SetSpacing(int horiz);
  105.       void SetSpacing();
  106.       // used to set horizontal and vertical character spacing. 
  107.       // SetSpacing() restores a nice-looking default.
  108.       // NOTE: Vertical spacing shows itself only when you use the new-line
  109.       // character (\n) inside your strings.
  110.  
  111.       void SetTranslation(char *translation_string);
  112.       // defines a translation table. Characters in the font file are
  113.       // addressed by a number: 0 for the first character, 1 for the
  114.       // second, etc. Calling the command:
  115.       // FontName.SetTranslation("AB.");
  116.       // would tell the library that is should print the character #0 when
  117.       // asked to print 'A', the character #1 when asked to print 'B', and
  118.       // the character #2 when asked to print '.'
  119.  
  120.       void SetSameChar(char c1, char c2);
  121.       // tells the library that the character c1 looks exactly like c2.
  122.       // The most common use is SetSameChar('0','O');
  123.  
  124.       void ChangeColor(unsigned char from_index, unsigned char to_index);
  125.       // Changes one of the colors used in the font. This function
  126.       // simply replaces all the pixels of the color "from_index" with
  127.       // pixels of the color "to_index". This procedure is quite slow, 
  128.       // but what else could I do? To find out what color you used when
  129.       // drawing the fonts, you'll have to look into the font files
  130.       // themselves.
  131.  
  132.       void Repaint(int n, ...);
  133.       // Replaces n colors used in the font by calling the ChangeColor
  134.       // function n times. This saves some space in the program, but
  135.       // does not provide any speed advantage. Warning: beware of chain
  136.       // changes! The command Repaint(3,1,2,2,3,3,4) will replace all the
  137.       // pixels of colors 1, 2 or 3 with pixels of color 4; it will *not*
  138.       // change 3 to 4, 2 to 3, and 1 to 2.
  139.  
  140.       void PutCh(int x, int y, char c);
  141.       void BPutCh(int x, int y, char c);
  142.       void CPutCh(int x, int y, char c);
  143.       void CBPutCh(int x, int y, char c);
  144.       // all these functions print a character #c at coordinates (x,y).
  145.       // Note: c is the number of the character in the font file, not the
  146.       // ASCII code or anything else.
  147.       // BPutCh is the fastest of all; it prints the character including
  148.       // the pixels of color 0 and does not care about clipping.
  149.       // CBPutCh does the same with clipping.
  150.       // PutCh and CPutCh are analogous, but do not display pixels of color
  151.       // 0, so the letters look "transparent". These two functions are
  152.       // slower, too.
  153.  
  154.       void Print(int x, int y, char *s);
  155.       void BPrint(int x, int y, char *s);
  156.       void CPrint(int x, int y, char *s);
  157.       void CBPrint(int x, int y, char *s);
  158.       // these functions print a string s at coordinates (x,y). Otherwise,
  159.       // they are similar to ...PutCh functions. The string may contain
  160.       // the new line character (\n).
  161.  
  162.       ----------
  163.       You may ask why on earth did I decide to write this library. The story
  164.       behind is the following: I needed to create a font for the game I was
  165.       working on (it's 70% percent complete, and I still hope to finish it).
  166.       So, I spent a couple of hours painting one just to find out that it 
  167.       was too big. Discrarding that font would have been stupid, though, 
  168.       so I wrote a quick and dirty library to support it. Here it is, 
  169.       together with the font (BIGFONT.FNT; 3DFONT.FNT is a smaller font
  170.       that I did later and will use in the game). The library is not very
  171.       fast and is probably more bugged than a room full of bugs, but it's
  172.       small, working, and free of charge.
  173.  
  174.       ----------
  175.       Send your comments, suggestions, bug reports, etc. to:
  176.  
  177.       Nikolai Soumarokov
  178.       Zschokkegasse 91/5/25
  179.       1220 Vienna, Austria
  180.  
  181.       phone/fax: (431) 283-7744
  182.